﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using S1._1_2.Apis;
using S1.Models;

namespace S1._1_2.ViewModels
{
    public class AddOrEditProductViewModel : Product
    {
        private readonly ProductApi _productApi;
        public AddOrEditProductViewModel()
        {
            _productApi = new ProductApi();

            SaveCommand = new RelayCommand(async () => await Save());
            CancelCommand = new RelayCommand(Cancel);

            //设置数据源
            CategorySources = new ObservableCollection<string>
            {
                "Bread",
                "Tarte",
                "Bread"
            };
        }
        private async Task Save()
        {
            await _productApi.AddNewProductAsync(this);
        }
        private void Cancel()
        {


        }
        [IgnoreDataMember]
        public ICommand SaveCommand { get; set; }
        [IgnoreDataMember]
        public ICommand CancelCommand { get; set; }

        [IgnoreDataMember]
        public ObservableCollection<string> CategorySources { get; set; }
    }
}
